package com.softeem.hello.controller;

import com.softeem.hello.entity.User;
import com.softeem.hello.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/login")
    public String login(String username,String password){
        boolean b = userService.login(username,password);
        return b ? "登录成功" : "账号或密码错误";
    }

    @RequestMapping("/reg")
    public  String reg(String username,String password){
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        boolean b = userService.registry(user);
        return b ? "注册成功" : "用户已存在";
    }

    @RequestMapping("/list")
    public List<User> list(){
        return  userService.list();
    }
}
